<template>
	<view class="wrap">
		<view class="photo-list" >
			<u-upload
					:previewFullImage="true"
					width="100"
					height="100"
					uploadIcon='plus'
					:fileList="fileList1"
					@afterRead="afterRead"
					@delete="deletePic"
					name="1"
					multiple
					:maxCount="9"
				></u-upload>
		</view>
		<u-button type="success" class="save-btn" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">保存</u-button>
		<view class="explain-box">
			<view class="explain-title u-flex">
				<view class="line"></view>
				<text>温馨提示</text>
			</view>
			<view class="explain-cont">
				<view class="explain-text">
					1、可在档案中留下联系方式，让更多人直接联系你，有助于提高成功率
				</view>
				<view class="explain-text">
					2、被搜索时排名靠前
				</view>
				<view class="explain-text">
					3、解锁“我的-收藏-收藏我的”功能
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList1: [],
				fileList3: [{
							url: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
						}],
			}
		},
		methods:{
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					setTimeout(() => {
						resolve( 'https://cdn.uviewui.com/uview/album/1.jpg' )
					}, 1000)
					/* let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					}); */
				})
			},
		}

	}
</script>

<style lang="less">
.wrap {
	display: flex;
	flex-direction: column;
	background: #fff;
	padding: 30upx;
}
.photo-list {
	display: flex;
	flex-direction: row;
	align-items: center;
	border-bottom: 1rpx solid #eee;
}
.save-btn{
	margin-top: 30upx;
	width: 500upx;
}
.explain-box{
		padding: 30upx 0;
		.explain-title{
			font-size: 30upx;
			font-weight: bold;
			align-items: center;
			.line{
				width: 6upx;
				height: 26upx;
				border-radius: 50upx;
				background-color: #f56c6c;
				margin-right: 10upx;
			}
		}
		.explain-cont{
			margin-top: 10upx;
			.explain-text{
				line-height: 50upx;
				font-size:28upx;
			}
		}
	}
</style>